<template>
    <div class="icons">
        <swiper  ref="mySwiper">
            <!-- slides -->
            <swiper-slide v-for="(page, index) of pages" :key="index">
                <div class="icon"  v-for="item in page" :key="item.id">
                    <div class="icon-content">
                        <img class="icon-img" :src="item.imgUrl" :alt="item.imgDesc">
                    </div>
                    <p class="icon-desc">{{item.imgDesc}}</p>
                </div>
            </swiper-slide>
        </swiper>
    </div>
</template>

<script>
export default {
  name: 'HomeIcon',
  props: {
    iconList: Array
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  },
  mounted () {

  }
}
</script>

<style lang="stylus" scoped>
 @import '~styles/varibles.styl'
 @import '~styles/mixins.styl'
 .icons >>> .swiper-container
   overflow:hidden
   height:0
   padding-bottom:50%
 .icon
     margin-top:.2rem
     position:relative
     overflow:hidden
     float: left
     width: 25%
     padding-bottom: 25%
     .icon-content
      position: absolute
      top: 0
      right: 0
      left: 0
      bottom:.44rem
      margin:.1rem
      box-sizing:border-box
      .icon-img
        display:block
        height:100%
        margin:0 auto
     .icon-desc
      position: absolute
      right: 0
      left: 0
      bottom:0
      line-height:.44rem
      height:0.44rem
      color:$darkTextColor
      text-align:center
      ellipsis()
</style>
